/**
 * @author JN
 * @Date: 2024-04-19
 * @LastEditTime: 2024-04-20
 * @description 组件大小
 */

import { defineStore } from 'pinia';
import { localCache } from "@/plugins/cache"

/**
 * 组件尺寸接口
 */
export interface ComSize {
    size?: string;
}

/**
 * 字体大小接口
 */
export interface FontSize {
    small: string;
    medium: string;
    large: string;
}

export const SizeMap = new Map().set("mini", {
    large: '16px',
    normal: '12px',
    mini: '10px'
}).set("normal", {
    large: '18px',
    normal: '14px',
    mini: '12px'
}).set("large", {
    large: '20px',
    normal: '16px',
    mini: '14px'
})

/**
 * 定义字体大小管理的 store
 */
export const useFontSizeChangeStore = defineStore({
    id: "fontSize",
    state: (): ComSize => ({
        size: localCache.get('fontSize') ?? 'normal'
    }),
    getters: {
        /**
         * 获取当前的字体大小配置
         * @returns 字体大小配置
         */
        getSize(): FontSize | undefined {
            return SizeMap.get(this.size)
        }
    },
    actions: {
        /**
         * 设置字体大小并保存到缓存
         * @param size - 字体大小
         */
        setSize(size: string) {
            localCache.set('fontSize', size);
            this.size = size
        }
    }
});